module.exports=new (function(){
    
    this.getHead=function(){
        return `declare module n {   
    interface Message{        
        encode(bytes:egret.ByteArray):egret.ByteArray;       
        decode(bytes:egret.ByteArray); 
        initialize(...arg);   
        reset();
        autoRecover:boolean;
        toPoolTime:number
    }\n`
    // +
    // `class MsgPool{        
    //     static from(id:number):Message;
    //     static fromContent(content:string):Message;
    //     static to(msg:Message,reset?:boolean);
    //     static getPool():any;
    //     static destroyExpiredObjects();
    // }\n`;
    }
    
    this.getMessageContentHead=function(name){return `    interface ${name} extends n.Message{\n`}
    this.getMessageContentEnd=function(){return `    }\n`;}

    this.getMapContentHead=function(){return `    class Map {\n        static initialize(): void;\n        static getMessage(routeId: number): any;\n`}
    this.getMapContentEnd=function(){return `    }\n`;}
    this.getMapContent=function(name,fileds){return `        static ${name.toLocaleUpperCase()}: number;\n`;}

    this.getEnd=function(){return `}`;}
    this.getMessageContent=function(fileds){
        var body="";
        for(var filed of fileds){
            body+="         "+filed.propertyName+" : "+this.getProperty(filed.type,filed.propertyType) +(filed.defaultValue?(" = "+filed.defaultValue):"")+"\n";
        }
        return body;
    }

    this.getProperty=function(type,propertyType){
        propertyType=this.getType(propertyType);
        if(type=='repeated'){
            propertyType+='[]'
        }
        return propertyType;
    }

    this.getType=function(propertyType){
        switch(propertyType){
            case 'string':
                return "string";
            case 'bool':
                return "boolean";
            case 'double':
            case 'float':
            case 'int32':
            case 'uin32':
            case 'int64':
            case 'uint64':
            case 'sint32':
            case 'sing64':
            case 'fixed32':
            case 'fixed64':
            case 'sfixed32':
            case 'sfixed64':
            case 'byte':
                return "number";
        }
        return propertyType;
    }

})()